package com.zzgc.modules.service.impl;

import com.zzgc.common.dao.AuthRightDao;
import com.zzgc.common.entity.AuthRight;
import com.zzgc.modules.service.AuthRightService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 菜单表(AuthRight)表服务实现类
 *
 * @author makejava
 * @since 2022-12-20 10:56:43
 */
@Service("authRightService")
public class AuthRightServiceImpl implements AuthRightService {
    @Resource
    private AuthRightDao authRightDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AuthRight queryById(Long id) {
        return this.authRightDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param authRight 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AuthRight> queryByPage(AuthRight authRight, PageRequest pageRequest) {
        long total = this.authRightDao.count(authRight);
        return new PageImpl<>(this.authRightDao.queryAllByLimit(authRight, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param authRight 实例对象
     * @return 实例对象
     */
    @Override
    public AuthRight insert(AuthRight authRight) {
        this.authRightDao.insert(authRight);
        return authRight;
    }

    /**
     * 修改数据
     *
     * @param authRight 实例对象
     * @return 实例对象
     */
    @Override
    public AuthRight update(AuthRight authRight) {
        this.authRightDao.update(authRight);
        return this.queryById(authRight.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.authRightDao.deleteById(id) > 0;
    }
}
